//
// Created by mac on 2019-08-09.
// Copyright (c) 2019 com.sw.village. All rights reserved.
//

#import "ChargeSubmitController.h"

@interface ChargeSubmitController()

@property(weak) IBOutlet UITextField *titleTextField;
@property(weak) IBOutlet UITextField *userTextField;
@property(weak) IBOutlet UITextField *phoneTextField;
@property(weak) IBOutlet UITextField *addressTextField;
@property(weak) IBOutlet UITextField *typeTextField;
@property(weak) IBOutlet UITextView *descTextView;
@property(weak) IBOutlet UIView *imagesItemsView;

@property (strong, nonatomic) NSMutableArray *imageUrls;


@end

@implementation ChargeSubmitController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.imageUrls = [NSMutableArray array];
    self.title = self.menuItem.title;
}
- (void)loadNetworkData {



}

- (IBAction)done {

    [SYProgressHUD show];
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    if (self.titleTextField.text) {
        [params addEntriesFromDictionary:@{@"title":self.titleTextField.text}];
    }
    if (self.userTextField.text) {
        [params addEntriesFromDictionary:@{@"username":self.userTextField.text}];
    }
    if (self.phoneTextField.text) {
        [params addEntriesFromDictionary:@{@"phone":self.titleTextField.text}];
    }
    if (self.addressTextField.text) {
        [params addEntriesFromDictionary:@{@"address":self.addressTextField.text}];
    }
    if (self.typeTextField.text) {
        [params addEntriesFromDictionary:@{@"type":self.typeTextField.text}];
    }
    if (self.descTextView.text) {
        [params addEntriesFromDictionary:@{@"desc":self.descTextView.text}];
    }
    if ([self.imageUrls count] > 0)  {
        [params addEntriesFromDictionary:@{@"images": [self.imageUrls componentsJoinedByString:@","]}];
    }

    [APIManager requestWithUrlString:@"api/charge/addItem" params:params method:@"POST" success:^(id response) {

        [SYProgressHUD showInfoText:@"提交成功"];
        [self.navigationController popViewControllerAnimated:YES];

    } failure:^(NSError *error) {
        [SYProgressHUD showFailureText:@"提交失败"];

    }];
}

@end
